package ch.bfh.abhmcm.SoftwareEngineeringAndDesign.view.mainframe.acceptRFCPanel.acceptRFCPanelSubs.listeners;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import ch.bfh.abhmcm.SoftwareEngineeringAndDesign.model.Workorder;
import ch.bfh.abhmcm.SoftwareEngineeringAndDesign.view.mainframe.acceptRFCPanel.AcceptRFCPanel;
import ch.bfh.abhmcm.SoftwareEngineeringAndDesign.view.mainframe.acceptRFCPanel.acceptRFCPanelSubs.ShowWorkorderDisplay;

public class OpenRFCButtonListener extends MouseAdapter implements
		ActionListener {

	private AcceptRFCPanel acceptRFCPanel;

	public OpenRFCButtonListener(AcceptRFCPanel acceptRFCPanel) {
		this.acceptRFCPanel = acceptRFCPanel;
	}

	private void action() {

		Workorder workorder = null;

		workorder = acceptRFCPanel.getListPanel().getApprovedDisplayTable()
				.getSelectedWoinTable();
		if (workorder == null) {
			workorder = acceptRFCPanel.getListPanel().getWorkingDisplayTable()
					.getSelectedWoinTable();
		}

		if (workorder != null) {

			new ShowWorkorderDisplay(acceptRFCPanel, workorder);
		}
	}

	@Override
	public void mouseClicked(MouseEvent arg0) {
		if (arg0.getClickCount() == 2) {

			this.action();
		}
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		this.action();

	}

}
